package org.jeecg.modules.user.member.util;


import java.math.BigDecimal;
import java.util.regex.Pattern;

/**
 * Description: 验证
 * Date: 2019-09-21 11:48
 **/

public class ValidKit {

    // 字符串是否为空
    public static boolean isEmpty(String val) {
        return null == val || val.length() <= 0;
    }

    public static boolean isEmpty(Integer val) {
        return null == val || val < 0;
    }

    public static boolean isEmpty(BigDecimal val) {
        return null == val;
    }

    /**
     * 判断字符串是否为数字
     *
     * @param val 字符串
     */
    public static boolean isNumber(String val) {
        Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$");
        return pattern.matcher(val).matches();
    }

    /**
     * 数值1是否大于数值2
     *
     * @param val1 数值1
     * @param val2 数值2
     * @return boolean
     */
    public static boolean isGt(BigDecimal val1, BigDecimal val2) {
        return val1.compareTo(val2) > 0;
    }


    /**
     * 判断一个数是否在数组内
     *
     * @param val  数
     * @param vals 数组
     * @return boolean
     */
    public static boolean inArray(int val, int... vals) {
        for (int value : vals) {
            if (value == val) return true;
        }
        return false;
    }


    /**
     * 判断一个数是否在数组内
     *
     * @param val  数
     * @param vals 数组
     * @return boolean
     */
    public static boolean inArray(String val, String... vals) {
        for (String str : vals) {
            if (str.equals(val)) return true;
        }
        return false;
    }


}
